home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SNIP0492.ARJ / 8087_SAV.ASM next >
Assembly Source File  |  1990-09-03  |  3KB  |  74 lines

  1. ; By: Jeffrey Nonken 
  2.  
  3.         page    60,132
  4.         .286
  5.  
  6. _text   segment byte public 'code'
  7. _text   ends
  8. _data   segment  word public 'data'
  9. _data   ends
  10. const   segment  word public 'const'
  11. const   ends
  12. _bss    segment  word public 'bss'
  13. _bss    ends
  14. dgroup  group   const,  _bss,   _data
  15.         assume  cs: _text, ds: nothing
  16.  
  17. _data   segment  word public 'data'
  18.         even
  19. env_8087        dw      47 dup (?)
  20. norm_8087       dw      177fh
  21. _data   ends
  22.  
  23. _text   segment byte public 'code'
  24. ;
  25. ; This code saves the 80x87 enviroment and sets up our own. First, this
  26. ; assumes you are running an 80287; the 8087 may require more FWAIT
  27. ; operations. Second, I decided that I didn't want to handle exceptions, so
  28. ; I simply disabled them. That means that if the 80x87 gets an invalid result
  29. ; (such as divide-by-zero) the 80x87 will continue to run and will produce
  30. ; invalid results until the end of your current calculation. Anything that
  31. ; depends on the results will, of course, also be invalid. If you want
  32. ; exceptions to be handled, get documentation for the 80x87 and you will
  33. ; see how to set norm_8087 (above) to suit your needs. If you are running
  34. ; an 8087 and don't know where to put FWAIT instructions, you can always
  35. ; add one after each floating-point instruction. NOTE: FWAIT is synonymous
  36. ; to WAIT. They are the same instruction.
  37. ;
  38. ; This was written for TURBO C and will also work with MSC. It should work
  39. ; with any programming language with no more than minor changes in the
  40. ; label names or the interface. Consult your compiler manual for more detail.
  41. ; I wrote this so it would work with either the tiny or small models.
  42. ; Actually, it will probably work with any of the models. You should be
  43. ; able to assemble this with MASM and link it right in.
  44. ;
  45. ; extern save_8087();
  46. ; extern restore_8087();
  47. ;
  48.         public  _save_8087
  49. _save_8087      proc    near
  50.         cli                             ; no interruptions!
  51.         lea     bx,dgroup:env_8087      ; point to save area
  52.         fwait                           ; make sure processor is ready
  53.         fnsave  [bx]                    ; save the 8087 environment
  54.         lea     bx,dgroup:norm_8087     ; point to our new 8087 setup
  55.         mov     ax,[bx]                 ; get it
  56.         fldcw   [bx]                    ; set it
  57.         fwait
  58.         sti                             ; restore interrupts
  59.         ret
  60. _save_8087      endp
  61.  
  62.         public  _restore_8087
  63. _restore_8087   proc    near
  64.         cli                             ; no interruptions!
  65.         lea     bx,dgroup:env_8087      ; point to saved 8087 stuff
  66.         frstor  [bx]                    ; restore the 8087 environment
  67.         sti                             ; restore interrupts
  68.         ret
  69. _restore_8087   endp
  70.  
  71. _text   ends
  72.  
  73.         end
  74.